package com.phonetools.commonutils.widget

import android.view.View
import android.widget.ScrollView
import android.widget.TextView

/**
 * ScrollView滚动到其内置的[view]的顶部
 * @param view
 */
fun ScrollView.scrollToBottomOf(view: View) {
    var offset = view.measuredHeight - this.measuredHeight
    if (offset < 0) offset = 0
    scrollTo(0, offset)
}

/**
 * ScrollView滚动到其内置的[textView]的最底部
 * @param textView
 */
fun ScrollView.scrollToBottomOfTextView(textView: TextView) {
    var offset = textView.lineCount * textView.lineHeight - this.measuredHeight
    if (offset < 0) offset = 0
    scrollTo(0, offset)
}